import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { SGuildWarehouseApply } from "../../../../../Message/Game/SGuildWarehouseApply";
import { ItemData } from "../../../resource/info/ItemData";
import { JSON } from "../../../../../com/mui/serialization/json/JSON";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { GuildEventName } from "../GuildEventName";
import { ObjCreate } from "../../common/ObjCreate";
import { BaseItem } from "../../common/BaseItem";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { EventName } from "../../../mvc/EventName";
import { _applyInfo } from "../../../../../this/_applyInfo";
import { _moneyMap } from "../../../../../this/_moneyMap";
//class ReplyRenderer
    
    export  class ReplyRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this._applyInfo = arg1 as SGuildWarehouseApply;
            if (this._applyInfo) 
            {
                if (this._applyInfo.itemCode > 0) 
                {
                    loc1 = new ItemData(this._applyInfo.itemCode);
                    loc1.itemAmount = this._applyInfo.amount;
                    if (this._applyInfo.jsStr != "") 
                    {
                        loc1.setItemExInfo(JSON.deserialize(this._applyInfo.jsStr));
                    }
                    this._baseItem.itemData = loc1;
                    this._name = ItemsUtil.getItemName(loc1);
                    this._moneyMap = null;
                }
                else 
                {
                    this._baseItem.itemData = null;
                    this._name = GameDefConfig.instance.getEPrictUnitName(this._applyInfo.unit);
                    if (this._applyInfo.unit == 0 || this._applyInfo.unit == 1) 
                    {
                        this._baseItem.source = GlobalClass.getBitmapData(ImagesConst.Market_Coin);
                    }
                    else if (this._applyInfo.unit == 2 || this._applyInfo.unit == 3) 
                    {
                        this._baseItem.source = GlobalClass.getBitmapData(ImagesConst.Market_Gold);
                    }
                    this._moneyMap = new Map<any, any> /* flash.utils.Dictionary */();
                    this._moneyMap[this._applyInfo.unit] = this._applyInfo.amount;
                }
                this._nameTxt.htmlText = this._name + "  *" + this._applyInfo.amount;
                this._playerNameTxt.htmlText = "<a href=\'event: 1\'><u>" + this._applyInfo.name + "</u></a>";
                this._playerNameTxt.addEventListener(flash.events.TextEvent.LINK, this.onPlayerNameClickHandler);
            }
            return;
        }

        /* internal  */onPlayerNameClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=0;
            if (this._applyInfo) 
            {
                loc1 = this._applyInfo.playerId;
                Dispatcher.dispatchEvent(new DataEvent(GuildEventName.AutoSelectedMember, loc1));
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 240, 50, this);
            this._nameTxt = ObjCreate.createTextField("", 67, 8, 170, 20, this);
            ObjCreate.createBg(14, 5, 38, 38, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.isDragAble = false;
            this._baseItem.width = 32;
            this._baseItem.height = 32;
            this._baseItem.move(16, 7);
            this.addChild(this._baseItem);
            this._amountTxt = ObjCreate.createTextField("", 140, 8, 170, 20, this);
            ObjCreate.createTextField(Language.getString(57272), 67, 30, 80, 20, this);
            this._playerNameTxt = ObjCreate.createTextField("", 120, 30, 170, 20, this, GlobalStyle.textFormat6);
            this._agreeBtn = ObjCreate.createGButton(Language.getString(57273), 188, 3, 49, 20, this);
            this._agreeBtn.name = "agree";
            this._agreeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
            this._agreeBtn.drawNow();
            this._refuseBtn = ObjCreate.createGButton(Language.getString(57274), 188, 26, 49, 20, this);
            this._refuseBtn.name = "refuse";
            this._refuseBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
            this._refuseBtn.drawNow();
            return;
        }

        /* internal  */onOperBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=false;
            if (this._applyInfo) 
            {
                loc1 = arg1.target as GButton;
                loc2 = false;
                if (loc1.name == "agree") 
                {
                    loc2 = true;
                }
                this.dispatchEvent(new DataEvent(EventName.OperateRequestInfo, {"applyInfo": _applyInfo, "result": loc2, "moneyMap": _moneyMap}, false, true));
            }
            return;
        }

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_amountTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_playerNameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_agreeBtn: GButton;

        /* internal */ /* var */_refuseBtn: GButton;

        /* internal */ /* var */_applyInfo: SGuildWarehouseApply;

        /* internal */ /* var */_name: string;

        /* internal */ /* var */_moneyMap: Map<any, any> /* flash.utils.Dictionary */;
    }
